<?php
namespace app\controllers;

use Yii;
use app\models\GameUser;
use app\controllers\BaseController;

class SocketController extends BaseController{
	public $enableCsrfValidation = false;
    //用于绑定client_id
	public static function actionSocket(){
		if( Yii::$app->request->isPost ){
            $postData = Yii::$app->request->post();
            $session = $postData['session'];
            $client_id = $postData['client_id'];
            $userdata = BaseController::judgeSession($session);
            if( !empty($userdata['code']) ){
                BaseController::sendClientId($client_id, $data);
                exit(0);
            }
            $userid = $userdata['id'];
            $groupid = 'Getup-room';
            //绑定userid和clientid
            BaseController::bind($client_id, $userid);
            //将客户client_id加入到组群中
            BaseController::joinGroup($client_id, $groupid);
            exit(0);
        }else{
            $content = "接收的posts数据为空";
            $data = array(
                '0' => -2,
                '1' => $content,
            );
            return BaseController::FailRespone($data);   
        }
	}
}